// component/worker-echarts-1/index.ts
import * as echarts from '../ec-canvas/echarts'
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    data: {
      type: Array,
      value: []
    }
  },
  observers: {
    "data": function (newVal) {
      // console.log('图表数据',newVal)
      // console.log(x,data,data2)
      this.setData({
        list: newVal,
        ec: {
          onInit: function (canvas, width, height, dpr) {
            const initChart = echarts.init(canvas, null, {
              width: width,
              height: height,
              devicePixelRatio: dpr
            });
            initChart.setOption({
              title: {
                text: '今日未完成工单统计',
                left: 0,
                top: 0
              },
              tooltip: {
                trigger: 'axis',
              },
              grid: {
                top: "60px",
                left: "0px",
                right: "0px",
                bottom: "70px",
                // height: '170',
                // top: 100,
                // left:'5%',
                containLabel: true
              },
              xAxis: {
                data: newVal.map(item => item.repairPreson),
              },
              yAxis: [
                {
                  name: '工单数量',
                  position: 'left',
                  axisLine: {
                    show: true,
                    lineStyle: {
                      // color: "#fff",
                    },
                  },
                  splitLine: { show: false },
                },
              ],
              series: [
                {
                  type: 'bar',
                  barMaxWidth: '10',
                  barMinWidth: '5',
                  data: newVal.map(item => item.countNum),
                  label: {
                    show: true, // 显示标签
                    position: 'top', // 标签的位置，这里是在柱子顶部
                    formatter: '{c}' // 标签内容格式器，{c} 表示数据值
                },
                },
              ],
            })
            canvas.setChart(initChart);
            return initChart;
          }
        }
      })
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    ec: {
      lazyLoad: true
    },
    list: []
  },

  /**
   * 组件的方法列表
   */
  methods: {

  },
  //小程序声明周期
  lifetimes: {
    attached: async function () {
      // 在组件实例进入页面节点树时执行
    },
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },
})